//
// Created by Administrator on 2021/5/15.
//
#include <stack>
#include <iostream>
#include <climits>
using namespace std;
class MinStack {
private:
    stack<int> x_stack{};  //数据栈
    stack<int> min_stack{};//辅助栈  记录此刻数据栈中的最小值
public:
    /** initialize your data structure here. */
    MinStack() {
        min_stack.push(INT_MAX);
    }

    void push(int val) {
        x_stack.push(val);
        min_stack.push(min(min_stack.top(),val));
    }

    void pop() {
        x_stack.pop();
        min_stack.pop();
    }

    int top() {
        return x_stack.top();
    }

    int getMin() {
        return min_stack.top();
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(x);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */

int main()
{
    auto obj = new MinStack();
    obj->push(-2);
    obj->push(0);
    obj->push(-3);
    cout << obj->getMin()<<endl;
    obj->pop();
    cout << obj->top()<<endl;
    cout << obj->getMin() << endl;
    delete obj;
    return 0;
}